package cn.edu.zut.sunday.blimp.func;

import cn.edu.zut.sunday.blimp.domain.DatasetName;
import cn.edu.zut.sunday.blimp.vo.DatasetNameVo;
import cn.edu.zut.sunday.utils.DateUtils;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;

@UtilityClass
public class DatasetNameTransformUtils {

    /**
     * 转换DatasetName实体对象成DatasetNameVo视图对象
     */
    public static final Function<DatasetName, DatasetNameVo> ENTITY_2_VO = datasetName -> {
        final DatasetNameVo datasetNameVo = new DatasetNameVo();
        datasetNameVo.setId(datasetName.getId());
        datasetNameVo.setDatasetName(datasetName.getSetName());
        datasetNameVo.setCount(datasetName.getDataCount());
        datasetNameVo.setMd5Info(datasetName.getMd5().substring(0, 10) + "...");
        datasetNameVo.setFileType(datasetName.getSuffix());
        datasetNameVo.setCreateTime(DateUtils.format(datasetName.getDateCreated()));
        datasetNameVo.setUpdateTime(DateUtils.format(datasetName.getDateModified()));

        return datasetNameVo;
    };

    /**
     * 转换DatasetName实体对象列表成DatasetNameVo视图对象列表
     */
    public static final Function<List<DatasetName>, List<DatasetNameVo>>
      LIST_ENTITY_2_VO = list -> list.stream()
      .map(DatasetNameTransformUtils.ENTITY_2_VO)
      .collect(Collectors.toList());
}
